package com.aynu.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author mj
 * @version 1.0
 * @date 2021/3/21 16:33
 */
public class OrderConfirmVo {
    /**
     * 收货地址列表，【ums_member_receive_address】表
     */
    @Getter @Setter
    private List<MemberAddressVo> memberAddressVoList;

    //所选中的购物项
    @Getter @Setter
    private List<OrderItemVo> orderItemVoList;

    //发票记录

    //优惠卷信息
    @Getter @Setter
    private Integer integration;

    //订单总额
    private BigDecimal total;

    //应付金额
    private BigDecimal payPrice;

    /**
     * 防重令牌
     */
    @Getter @Setter
    private String orderToken;

    /**
     * 总件数
     */
    private Integer count;

    @Getter @Setter
    private Map<Long,Boolean> stocks;

    /**
     * 计算订单总额
     * @return
     */
    public BigDecimal getTotal() {
        BigDecimal totalNum = BigDecimal.ZERO;
        if (orderItemVoList != null && orderItemVoList.size() > 0) {
            for (OrderItemVo item : orderItemVoList) {
                //计算当前商品的总价格
                BigDecimal itemPrice = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                //再计算全部商品的总价格
                totalNum = totalNum.add(itemPrice);
            }
        }
        return totalNum;
    }

    public BigDecimal getPayPrice() {
        return getTotal();
    }

    public Integer getCount() {
        Integer count = 0;
        if (orderItemVoList != null && orderItemVoList.size() > 0) {
            for (OrderItemVo item : orderItemVoList) {
                count += item.getCount();
            }
        }
        return count;
    }
}